package com.cskaoyan.service;

import com.cskaoyan.bean.MarketBrand;
import com.cskaoyan.bean.MarketBrandExample;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.vo.WxBrandVo;
import com.cskaoyan.mapper.MarketBrandMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Fyy
 * @since 2023/01/01 17:13
 */
@Service
public class WxBrandServiceImpl implements WxBrandService {
    @Autowired
    MarketBrandMapper brandMapper;

    /**
     * 品牌列表
     * @param basePageInfo
     * @return
     */
    @Override
    public CommonData<MarketBrand> list(BasePageInfo basePageInfo) {
        //分页
        PageHelper.startPage(basePageInfo.getPage(), basePageInfo.getLimit());
        //根据传入值给example赋值
        MarketBrandExample example = new MarketBrandExample();
        MarketBrandExample.Criteria criteria = example.createCriteria();
        //只查询逻辑未删除的数据
        criteria.andDeletedEqualTo(false);
        //查询
        List<MarketBrand> brandList = brandMapper.selectByExample(example);
        //封装返回值
        PageInfo<MarketBrand> pageInfo = new PageInfo<>(brandList);
        return CommonData.data(pageInfo);
    }

    /**
     * 品牌详情
     * @param id
     * @return
     */
    @Override
    public MarketBrand detail(Integer id) {
        MarketBrand marketBrand = brandMapper.selectByPrimaryKey(id);
        return marketBrand;
    }
}
